<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page language="java" import="com.server.web.JsVersionUtil"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="UTF-8" />
<title>管理人员管理列表</title>
<script
	src='<c:url value="/js/boot.js"></c:url>?v=<%=JsVersionUtil.CURRENT_VERSION%>'></script>
<script
	src='<c:url value="/js/rqfui/rqfui.js"></c:url>?v=<%=JsVersionUtil.CURRENT_VERSION%>'></script>
<link rel="stylesheet" type="text/css"
	href='<c:url value="/share/styles.css"></c:url>?v=<%=JsVersionUtil.CURRENT_VERSION%>' />
<style type="text/css">
body, html {
	width: 100%;
	height: 100%;
	margin: 0;
	font-family: "微软雅黑";
}

p {
	margin-left: 5px;
	font-size: 14px;
}

body {
	height: 100%;
	overflow: hidden;
}

.filterPan td {
	padding: 0;
}

.mini-splitter-pane {
	overflow: auto;
}

.mini-panel-body {
	padding: 0;
}

html body .searchbox .mini-buttonedit-icon {
	background: url('<c:url value="/share/img/magnifier-zoom.png"></c:url>')
		no-repeat 5% 5%;
}

.nameTitle {
	color: red;
}

.state0 {
	font-color: #000000;
	background-color: light-gray;
}
.state1,.state3{
	font-color: #000000;
	background-color: #FFFBD0;
}

.state2,.state4 {
	font-color: #000000;
	background-color: #FFEBE6;
	color: red;
}

.state5 {
	font-color: #000000;
	background-color: #E0FFD0;
}
</style>
<script type="text/javascript">
	var sexData = [ {'text':'男'},{'text':'女'}];
	var stateData = ['未使用','已使用'];
</script>
</head>

<body>
	<div class="mini-toolbar"
		style="padding: 0px; border-width: 1px; border-bottom-width: 0px;">
		<table style="width: 100%;">
			<tr>
				<td style="width: 5px; height: 23px;"></td>
				<td width="500px"><a class="mini-button" id="rebackBtn"
					plain="true" iconCls="icon-list" onclick="status1">返回列表</a>
					</div> <a class="mini-button" id="addBtn"
					iconCls="icon-addnew" plain="true" onclick="add">新增</a>
					<a class="mini-button" id="editBtn"
					iconCls="icon-edit" plain="true" onclick="edit">编辑</a><a class="mini-button"
					id="deleteBtn" iconCls="icon-cancel" plain="true"
					onclick="deleteRows">删除</a> <a class="mini-button"
					id="toEsBtn" iconCls="icon-upload" plain="true"
					onclick="toEstimate">提交评估</a> <a class="mini-button" id="resetBtn"
					iconCls="icon-reset" plain="true" onclick="reloadList">刷新</a>
					<a id="submintBtn" class="mini-button" iconCls="icon-ok" style="width: 60px;" onclick="ok()">确定</a></td>
				<td style="width: 80px; height: 100%;">
					<div class="pageStatContainer">
						<div id="pageStatBtn_list"
							class="pageStat pageStatList pageStatListPress">
							<p>1</p>
						</div>
						<div id="pageStatBtn_form" class="pageStat pageStatForm">
							<p>2</p>
						</div>
						<div id="pageStatBtn_split" class="pageStat pageStatSplit">
							<p>3</p>
						</div>
					</div>
				</td>
			</tr>
		</table>
	</div>
	<div class="mini-fit">
		<div id="splitterPan" class="mini-splitter"
			style="width: 100%; height: 100%;" handlerSize="0">
			<div id='panLeft' size="400" showCollapseButton="true"
				style="padding: 0px; height: 100%; width: 100%;">
				<div id="datagrid1" class="mini-datagrid gridFull"
					borderStyle="border:1;" showReloadButton="true" pagesize="100"
					sizeList="[20,50,100,200]" allowCellWrap="true"
					allowHeaderWrap="true" idField="No" multiSelect="true"
					showPager="true" allowAlternating="true"
					ondrawcell="ondatagrid1DrawCell" onrowdblclick="gridRowDbClick"
					style="height: 100%; width: 100%; -moz-user-select: none; -webkit-user-select: none;"
					collapseGroupOnLoad="false" showColumnsMenu="true"
					showFilterRow="true" onshowrowdetail="onShowRowDetail">
					<div property="columns">
						<div type="indexcolumn" width="40px"></div>
						<div type="checkcolumn" width="40px" align="center"></div>
						<div field="Action" width="70px" headerAlign="center"
							align="center">
							<a class="mini-button" property="filter" id="removeBtn"
								iconCls="icon-broom" tooltip="清除筛选" onclick="removeSearch">清除
							</a>
						</div>
						<div field="work_place" width="100px" headerAlign="center"
							align="left" allowSort="true">
							机构名称<input id="filter3" property="filter"
								class="mini-buttonedit searchbox" style="width: 100%;"
								onbuttonclick="onselect" emptyText="筛选..." onenter="onselect" />
						</div>
						<div field="mobile_phone" width="100px" headerAlign="center"
							align="left" allowSort="true">
							联系电话
						</div>
						<div field="name" width="80px" headerAlign="center"
							align="left" allowSort="true">
							联系人<input id="filter0" property="filter"
								class="mini-buttonedit searchbox" style="width: 100%;"
								onbuttonclick="onselect" emptyText="筛选..." onenter="onselect" />
						</div>
						<div field="sex" width="200px" headerAlign="center"
							align="left" allowSort="true">
							性别<input id="filter1" property="filter"
								class="mini-combobox" style="width: 100%;"
								textField="text" valueField="text"
								data="sexData" showNullItem="true" 
								 emptyText="全部" onvaluechanged="onselect" 
								allowInput="false" />
						</div>
						<div field="post" width="110px" headerAlign="center"
							align="left" allowSort="true" dateFormat="yyyy-MM-dd">
							职务
						</div>
						<div field="email" width="160px" headerAlign="center"
							align="left" allowSort="true">
							邮箱地址
						</div>
						<div field="useFlag" width="60px" headerAlign="center"
							align="left" allowSort="true">
							状态
						</div>
						<div field="nickname" width="100px" headerAlign="center"
							align="left" allowSort="true">
							账号名
						</div>
						<div field="creater" width="65px" headerAlign="center"
							align="center" allowSort="true">添加人</div>
						<div field="createTime" width="85px" dateFormat="yyyy-MM-dd"
							headerAlign="center" align="center" allowSort="true">添加日期</div>
						<div name="emptyCol" width='100%' headerAlign="center"
							align="center" cellStyle="padding:0;"></div>
					</div>
				</div>
			</div>
			<div id="panRight" showCollapseButton="true" expanded="false"
				style="overflow: hidden;">
				<iframe id=detailPan class="subPageFrame" frameborder="0">
				</iframe>
			</div>
		</div>
	</div>
	<script type="text/javascript">
		mini.parse();

		mini_debugger = false;
		var isKeepStat3 = false;

		var rootPath = '${rootPath}';
		var type='${type}';
		var data = new Object();
		var filterHelper = gridFilter();

		var datagrid1 = mini.get("datagrid1");
		var splitpan = mini.get("splitterPan");
		var typeBtn = mini.get("typeBtn");
		var filter0 = mini.get("filter0");
		var filter1 = mini.get("filter1");
		var filter3 = mini.get("filter3");

		$(function() {
			$(".pageStat").hover(function() {
				$(this).addClass("hoverStyle");
			}, function() {
				$(this).removeClass("hoverStyle");
			});
			$(".pageStat").click(
					function() {
						$this = $(this);
						var value = $this.find("p").first().html();
						if (value == 1) {
							splitpan.collapsePane(2);
							$this.addClass("pageStatListPress");
							$this.next().removeClass("pageStatFormPress")
									.next().removeClass("pageStatSplitPress");
							isKeepStat3 = false;
							status1Show();
						}
						if (value == 2) {
							splitpan.collapsePane(1);
							$this.addClass("pageStatFormPress");
							$this.prev().removeClass("pageStatListPress");
							$this.next().removeClass("pageStatSplitPress");
							isKeepStat3 = false;
							status2Show();
						}
						if (value == 3) {
							splitpan.expandPane(1);
							splitpan.expandPane(2);
							$this.addClass("pageStatSplitPress");
							$this.prev().removeClass("pageStatFormPress")
									.prev().removeClass("pageStatListPress");
							isKeepStat3 = true;
							status3Show();
						}
					});
			status1();
			loadGrid1();
		});
		function add() {
			showDetail(0,0);
		}
		//双击
		function gridRowDbClick(e) {
			var id = e.row.id;
			var state = e.row.state;
			showDetail(id,state);
		}
		function showDetail(id,state) {
			status2();
			var url = null;
			if(!id || id == 0){
				url = '<c:url value="/adminUser/add/1" />';
			}else{
				if(state == 0){
					url = '<c:url value="/adminUser/update/" />'+id;
				}else{
					url = '<c:url value="/adminUser/check/" />'+id+"/0/1";
				}
			}
			$('#detailPan').css('height', '100%').css('width', '100%').attr(
					'src', url);
		}
		//删除
		function deleteRows(){
			var rows = datagrid1.getSelecteds();
			if(rows.length < 1){
				mini.alert("请选择至少一条记录！");
				return;
			}
			var ids = "";
			for(var i=0; i<rows.length; i++){
				if(rows[i].useFlag){
					mini.alert("信息被使用！");
				}else{
					ids += rows[i].id;
					if(i != rows.length-1){
						ids += ',';
					}
				}
			}
			if(ids){
	        mini.confirm("确定删除？", "删除后不可恢复！",
	            function (action) {
	                if (action == "ok") {
			        	var messageid = mini.loading("删除中...", "Loading");
						$.ajax({
							url : '<c:url value="/adminUser/delete" />',
							type : "post",
							dataType : 'json',
							data : {
								"ids" : ids
							},
							success : function(text) {
								if (text > 0) {
									top.commonTools.showTip("删除成功", 1);
									reloadList();
								}else{
									top.commonTools.showTip("删除出错！", 2);
								}
							},
							complete : function(XMLHttpRequest, textStatus) {
								if(messageid){
									mini.hideMessageBox(messageid);
								}
							},
							error : function() {
								top.commonTools.showTip("操作发生错误", 2);
							}
						});
	                } else {
	                }
	            }
	        );
			}
		}
		//编辑
		function edit(){
			var rows = datagrid1.getSelecteds();
			var length = rows.length;
			if(length < 1){
				mini.alert("请选择至少一条记录！");
				return;
			}else if(length > 1){
				mini.alert("只能选择一条记录！");
				return;
			}
			var row = rows[0];
			var id = row.id;
			if(!id){
				mini.alert("数据有误，请联系管理员处理！");
				return;
			}
			status2();
			var url = '<c:url value="/adminUser/update/" />'+id+'/0/1';
			$('#detailPan').css('height', '100%').css('width', '100%').attr(
					'src', url);
		}
		function onselect() {
			var filterValue0 = filter0.getValue();
			var filterValue1 = filter1.getValue();
			var filterValue3 = filter3.getValue();
			filterHelper.clearFilterData();
			if (filterValue0 != "") {
				var filterdata = filterHelper.formFilterData("name",
						filterValue0, '', 'CONTAIN', 'AND');
				filterHelper.addFilterData(filterdata);
			}
			if (filterValue1 != "") {
				var filterdata = filterHelper.formFilterData("sex",
						filterValue1, '', 'EQUALS', 'AND');
				filterHelper.addFilterData(filterdata);
			}
			if (filterValue3 != "") {
				var filterdata = filterHelper.formFilterData("work_place",
						filterValue3, '', 'CONTAIN', 'AND');
				filterHelper.addFilterData(filterdata);
			}
			loadGrid1();
		}
		function loadGrid1() {
			var filterData = filterHelper.getFilterData();
			var postData = new Object();
			if (filterData != null || filterData.length > 0) {
				postData.filterdata = mini.encode(filterData);
			}
			//var type = typeBtn.getValue();
			var url = "<c:url value='/adminUser/list' />";
			datagrid1.load(url);
			datagrid1.load(postData);
		}
		function removeSearch() {
			filter0.setValue();
			filter0.setText();
			filter1.setValue();
			filter1.setText();
			filter3.setValue();
			filter3.setText();
			filterHelper.clearFilterData();
			loadGrid1();

		}
		function ondatagrid1DrawCell(e) {
			var row = e.row;
			var field = e.field;
			var state = row.useFlag;
			
			e.cellCls = "state"+state;

			if (field == "Action") {
				var id = row.id;
				e.cellHtml = '<a class="aTagUnderLine" href="javascript:showDetail('
						+ id + ',1)">[详细]</a>';
			}
			if (field == "useFlag") {
				if(state){
					e.cellHtml = stateData[1];
				}else{
					e.cellHtml = stateData[0];
				}
				
			}
			if(field == "time"){
				var value = e.value;
				if(value){
					value = commonTools.dateGMTToStr(value, "yyyy-MM-dd");
				}else{
					value = "";
				}
				e.cellHtml = value;
			}
		}

		function status1() {
			if (!isKeepStat3) {
				$("#pageStatBtn_list").click();
			}
		}
		function status2() {
			if (!isKeepStat3) {
				$("#pageStatBtn_form").click();
			}
		}
		function status3() {
			$("#pageStatBtn_split").click();
		}
		function status1Show() {
			$('#rebackBtn').hide();
			$('#typeBtn').hide();
			
			if(type==2){
				$("#addBtn").hide();
			}else{
				$("#addBtn").show();
			}
			if(type==2){
				$("#editBtn").hide();
			}else{
				$("#editBtn").show();
			}
			if(type==2){
				$("#deleteBtn").hide();
			}else{
				$("#deleteBtn").show();
			}
			if(type==2){
				$("#submintBtn").show();;
			}else{
				$("#submintBtn").hide();
			}
			$("#toEsBtn").hide();
			$('#resetBtn').show();
		}
		function status2Show() {
			$('#rebackBtn').show();
			$('#typeBtn').hide();
			$("#addBtn").hide();
			$("#editBtn").hide();
			$("#deleteBtn").hide();
			$("#toEsBtn").hide();
			$('#resetBtn').hide();
			$("#submintBtn").hide();
		}
		function status3Show() {
			$('#rebackBtn').hide();
			$('#typeBtn').hide();
			$("#addBtn").show();
			$("#editBtn").show();
			$("#deleteBtn").show();
			$("#toEsBtn").hide();
			$('#resetBtn').show();
			$("#submintBtn").hide();
		}
		function reloadList() {
			datagrid1.reload();
		}
		//确定
		function ok(){
			var names = null;
			var uuids = null;
			var phoneNos = null;
			var rows1 = datagrid1.getSelecteds();
			var length1 = rows1.length;
			if(length1 == 0){
				top.commonTools.showTip("请选择人员！", 2);
				return;
			}
			for(var i=0; i<length1; i++){
				var row = rows1[i];
				var nickname = row.nickname;
				if(names == null){
					if(nickname){
						names = nickname+"(管理员)";
					}else{
						names = "无";
					}
				}else{
					names += ','+nickname+'(管理员)';
				}
				var uuid = row.uuid;
				if(uuids == null){
					if(uuid){
						uuids = uuid;
					}else{
						uuids = "无";
					}
				}else{
					uuids += ','+uuid;
				}
				var phoneNo = row.mobile_phone;
				if(phoneNos == null){
					if(phoneNo){
						phoneNos = phoneNo;
					}else{
						phoneNos = "无";
					}
				}else{
					phoneNos += ','+phoneNo;
				}
			}
			if(uuids == null){
				top.commonTools.showTip("没有可添加的人员！", 2);
				return;
			}
			data.names = names;
			data.uuids = uuids;
			data.phoneNos = phoneNos;
			CloseWindow('ok');
		}
		function CloseWindow(action) {
			if (window.CloseOwnerWindow)
				return window.CloseOwnerWindow(action);
			else
				window.close();
		}
	</script>
</body>
</html>